package com.qfedu.service.impl;

import com.qfedu.mapper.ProjectMapper;
import com.qfedu.model.Project;
import com.qfedu.page.PageResult;
import com.qfedu.page.QueryPageBean;
import com.qfedu.page.Result;
import com.qfedu.service.ProjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @author LiJH
 * @date 2023-02-10
 */
@Service
public class ProjectServiceImpl implements ProjectService {
    @Autowired
    private ProjectMapper projectMapper;
    @Override
    public PageResult findPage(QueryPageBean queryPageBean) {

        PageResult pageResult = new PageResult();
        Integer currentPage = queryPageBean.getCurrentPage();
        Integer pageSize = queryPageBean.getPageSize();
        long count = projectMapper.count();
        pageResult.setTotal(count);
        List<Project> page = projectMapper.findPage((currentPage - 1) * pageSize, pageSize);
        pageResult.setRows(page);
        return pageResult;
    }

    @Override
    public List<Project> findAll() {
        List<Project> all = projectMapper.findAll();
        return all;
    }

    @Override
    public int addProject(Project project) {
        project.setUpdatetime(new Date());
        return projectMapper.addProject(project);
    }

    @Override
    public Project findById(int pid) {
        return   projectMapper.findById(pid);
    }

    @Override
    public int editProject(Project project) {
        project.setUpdatetime(new Date());
        int i = projectMapper.editProject(project);
        return i;
    }

    @Override
    public int deleteByPid(int pid) {
        return projectMapper.deleteByPid(pid);
    }

    @Override
    public Project index(int pid) {
        Project index = projectMapper.index(pid);
        return index;
    }

}